package com.skycode6.servlet;

import com.skycode6.bean.AdminBean;
import com.skycode6.dao.AdminDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/adminUser.jsp")
public class AdminServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");//请求参数类型设置
        String sp = req.getParameter("page");//前端的参数都是String类型
        int page = 1;
        if (sp  != null && !sp.equals("")){//传了情况下
            page = Integer.parseInt(sp);//将前端字符数字强制转化为整形
        }
        AdminDao  adminDao = new AdminDao();
        List<AdminBean> list = adminDao.getList(page);//分页查询
        req.setAttribute("list", list);

        req.getRequestDispatcher("WEB-INF/news.jsp").forward(req, resp);
    }
}
